<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace app\common\library\wechat;

use app\common\library\helper;

/**
 * 微信小程序api
 * Class WxApi
 * @package app\common\library\wechat
 */
class WxApi extends WxBase
{
    /**
     * 根据不同渠道生成不同二维码
     * @param $scene
     * @return array|false
     * @throws \cores\exception\BaseException
     *
     */
    public function WxCode($scene) {
        $access_token = $this->getAccessToken();
        $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token;
        $data['scene'] = 'channelName='.$scene;
        //小程序的详情页路径
        $data['page'] = 'pages/index/index';
        //$data['env_version'] = 'develop';
        //二维码大小
        $data['width'] = '430';
        $result = $this->post($url, json_encode($data));
        if(empty($result)){
            return false;
        }
        $path = 'uploads/10001/wxcode/';
        if(!file_exists($path)){
            mkdir($path, 0755, true);
        }
        $file_name = $scene.'.png';
        file_put_contents($path.$file_name, $result);
        $return['status_code'] = 200;
        $return['msg'] = 'ok';
        $return['img'] = '/' . $path.$file_name;
        return $return;
    }

}